﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace SimplePlainTextEditor
{
    public partial class ucMain : UserControl
    {
        public ucMain()
        {
            Debug.WriteLine(DateTime.Now + " DEBUG: PLugin SimplePlainTextEditor.dll běží v {0} s  AppDomainID = {1}.", Thread.GetDomain().FriendlyName, Thread.GetDomainID());
            InitializeComponent();
            //this.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
            //| System.Windows.Forms.AnchorStyles.Left)
            //| System.Windows.Forms.AnchorStyles.Right)));
            this.Dock = System.Windows.Forms.DockStyle.Fill;
        }

        private void linkOpenFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Clear();
                System.IO.TextReader tr = File.OpenText(openFileDialog1.FileName);
                this.textBox1.Text = tr.ReadToEnd();
                tr.Close();
            }
        }

        private void linkSaveFile_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (System.IO.File.Exists(openFileDialog1.FileName))
            {
                openFileDialog1.FileName = saveFileDialog1.FileName;
            }

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                StreamWriter sw = new FileInfo(saveFileDialog1.FileName).CreateText();
                sw.Write(this.textBox1.Text);
                sw.Flush();
                sw.Close();
            }
        }



    }
}
